// pages/payewm/payewm.js
var http = require('../../utils/http.js');
var unionid = wx.getStorageSync('thisCode');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    changeFlge:true,
    imgUrl:http.imgUrl,
    rebT:-100,
    transiFlag:true
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    let type = options.type;
    let changeFlge = type==1?false:true;
    this.setData({changeFlge:changeFlge});
    if(changeFlge){
      this.requireData(1,0)
      this.setData({coupon_id:0,thisType:1})
    }else{
      let coupon_id = options.coupon_id
      this.requireData(2,coupon_id)
      this.setData({coupon_id:coupon_id,thisType:2})
    }
    let shuaxin = setInterval(()=>{
      this.requireData(this.data.thisType,this.data.coupon_id);
    },120000)
    this.setData({shuaxin:shuaxin})
  },
  requireData(type,coupon_id){
    var unionid = wx.getStorageSync('thisCode');
    wx.showLoading({
      title: '加载中...',
    })
    http._post('PaymentCode/code',{type:type,coupon_id:coupon_id,unionid:unionid},res=>{
      let data = res.data;
      if(data.status == 1){
        this.setData({
          payewmInfo:data.info
        })
      }
    },res=>{})
  },
  clickPageLoding(){
    this.requireData(this.data.thisType,this.data.coupon_id)
    this.setData({coupon_id:this.data.coupon_id,thisType:this.data.thisType})
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {
  
  },
  // 点击关闭
  hideRedB(){
    this.setData({rebT:200,transiFlag:true});
    setTimeout(()=>{
      this.setData({rebT:-100,transiFlag:false})
    },500)
  },
  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
    wx.hideShareMenu();
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {
    clearInterval(this.data.shuaxin)
  },
  // 点击更改状态
  changeEwmBtn(e){
    let index = http.dataIndex(e)[0];
    if(index==0){
      this.setData({changeFlge:true})
      this.requireData(1,0)
      this.setData({coupon_id:0,thisType:1})
    }else{
      wx.redirectTo({
        url: "/pages/cardBag/cardBag?payEwm=1",
      })
    }
    
  },
  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {
    clearInterval(this.data.shuaxin)
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {
  
  },

})